package edu.bu.cs673.superkids123.children.view.lessons;

import java.awt.*;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.SwingConstants;

import edu.bu.cs673.superkids123.AbstractFrame;
import edu.bu.cs673.superkids123.AbstractView;
import edu.bu.cs673.superkids123.children.controller.AchievementController;
import edu.bu.cs673.superkids123.children.controller.lessons.LessonResultsController;

import edu.bu.cs673.superkids123.children.model.resources.ChildrenResource;
import edu.bu.cs673.superkids123.children.model.resources.ChildrenResourceProvider;
import edu.bu.cs673.superkids123.children.view.components.AchievementsEarnedPanel;
import edu.bu.cs673.superkids123.common.model.Achievement;
import edu.bu.cs673.superkids123.common.model.Child;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * NumberMatchingGameController
 * @author Harris Tracy
 *
 */

public class LessonResultsView extends AbstractView<JPanel> 
implements ActionListener
{
	//private JButton parentsButton;
	private JLabel encouragementField;
	private JButton returnToMenuButton; 
	private ImageIcon encouragementImage;
	private Child child;
	
	public LessonResultsView(AbstractFrame mainFrame) {
		super(mainFrame);
	}
	/**
	 * @wbp.parser.entryPoint
	 */

	@Override
	protected JPanel layout() {
		JPanel p = new JPanel();
		p.setSize(800, 600);
		p.setBackground(Color.WHITE);
		GridBagLayout gbl_p = new GridBagLayout();
		gbl_p.columnWidths = new int[]{100, 537, 116};
		gbl_p.rowHeights = new int[]{70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		p.setLayout(gbl_p);
		
		ChildrenResourceProvider provider = ChildrenResourceProvider.getInstance();
		
		child = (Child) authController.getCurrentUser();
		encouragementImage = provider.getImage(ChildrenResource.imageEncouragementSmile);
		
		JPanel pic = new JPanel();  
		pic.setBorder(null);
		pic.setBackground(Color.WHITE);
		pic.setSize(100,100);  
		  
		GridBagConstraints gbc_pic = new GridBagConstraints();
		gbc_pic.insets = new Insets(0, 0, 5, 5);
		gbc_pic.gridx = 0;
		gbc_pic.gridy = 0;
		p.add(pic, gbc_pic);   
		encouragementField = new JLabel("GOOD JOB, ".concat(child.getName().concat("!!")), JLabel.CENTER);
		
		//encouragementField for encouraging message 
		encouragementField.setBackground(Color.WHITE);
		encouragementField.setFont(new Font("Arial", Font.PLAIN, 56));
		GridBagConstraints encouragementConstraints = new GridBagConstraints();
		encouragementConstraints.insets = new Insets(0, 0, 5, 5);
		encouragementConstraints.gridx = 1;
		encouragementConstraints.gridy = 0;
		p.add(encouragementField, encouragementConstraints);
		
		JLabel lab = new JLabel(encouragementImage, SwingConstants.CENTER);
		GridBagConstraints gbc_lab = new GridBagConstraints();
		gbc_lab.fill = GridBagConstraints.BOTH;
		gbc_lab.insets = new Insets(0, 0, 5, 5);
		gbc_lab.gridx = 1;
		gbc_lab.gridy = 4;
		p.add(lab, gbc_lab);
		
		//returnToMenuButton for navigation to activities menu  
		returnToMenuButton = new JButton ("Return to the Main Menu"); 
		GridBagConstraints returnToMenuConstraints = new GridBagConstraints();
		returnToMenuConstraints.insets = new Insets(0, 0, 0, 5);
		returnToMenuConstraints.gridx = 1;
		returnToMenuConstraints.gridy = 7;
		p.add(returnToMenuButton,returnToMenuConstraints);
		
		// Earned Achievements
		List<Achievement> earned = getMainFrame().getController(LessonResultsController.class)
				.getEarnedAchievements();
		if (earned != null && earned.size() > 0) {
			AchievementsEarnedPanel earnedPanel = new AchievementsEarnedPanel(earned);
			GridBagConstraints gbc_earned = new GridBagConstraints();
			gbc_earned.insets = new Insets(0, 0, 0, 5);
			gbc_earned.gridx = 1;
			gbc_earned.gridy = 9;
			p.add(earnedPanel, gbc_earned);
		}
		
		returnToMenuButton.addActionListener(this);
		
		return p;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() instanceof JButton) {
			if (e.getSource() == returnToMenuButton) {
				getMainFrame().getController(LessonResultsController.class)
				.returnToMenuButtonPressed();
			} //else if (e.getSource() == parentsButton) {
				//getMainFrame().getController(LessonResultsController.class)
				//.parentsButtonPressed();
				}
			}
		}
//	}